<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/Paging.tld" prefix="pagingTag"%>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags"%>
<head>
	<title>Tạo tài khoản</title>
	<script type="text/javascript">
		$(function(){
			//lay thong bao notice
		  	var notice = $.getUrlVar('notice');
			if (notice != null || notice != "") {
				if(notice=="emailAlreadyExists"){
					$("#notice").html("Email đã tồn tại!");
					$("#notice").fadeOut(5000);
				}else if(notice=="nickNameAlreadyExists"){
					$("#notice").html("Nick name đã tồn tại!");
					$("#notice").fadeOut(5000);
				}else if(notice=="successfully"){
					$("#notice").html("Tạo tài khoản thành công.");
					$("#notice").fadeOut(5000);
				}else if(notice=="error"){
					$("#notice").html("Dữ liệu truyền vào chưa chính xác.");
					$("#notice").fadeOut(5000);
				}
			}
			//end
			//check email
			$("#email").change(function(){
				var val = $(this).val();
				if(val!=null && val != ""){
					$.ajax({
						type:"post",
						url:'<spring:url value="/check-account.htm" />',
						data:{cl:"email",val:val},
						async:false,
						success:function(rs){
							if(rs){
								$(".checkEmail").html("Email này đã đc đăng ký.");
								$(this).css("border","1px solid red");
							}
						}
						
					});
				}
			});
			//check nickname
			$("#nickName").change(function(){
				var val = $(this).val();
				if(val!=null && val != ""){
					$.ajax({
						type:"post",
						url:'<spring:url value="/check-account.htm" />',
						data:{cl:"nickName",val:val},
						async:false,
						success:function(rs){
							if(rs){
								$(".checkNickName").html("Nick name này đã đc sử dụng.");
								$(this).css("border","1px solid red");
							}
						}
						
					});
				}
			});
		});
	</script>
</head>
<body>
	<section class="form">
		<form action="<spring:url value="/quan-ly/tai-khoan/xu-ly-tao-tai-khoan.htm" />" method="post">
			<fieldset>
				<legend>Tạo tài khoản</legend>
				<section>
					<label>Quyền: </label>
					<select name="level" id="level">
						<option value="2" selected="selected">Thành viên</option>
						<option value="3">Nội dung</option>
						<option value="4">Super Mod</option>
						<option value="5">Admin</option>
					</select>
				</section>
				<section>
					<label for="nickName">Nick name : </label><span class="checkNickName" style="color:red"></span>
					<input type="text" value="${nickName}" id="nickName" name="nickName" class="validate[required]" placeholder="Nick name..." />
				</section>
				<section>
					<label for="email">Email : </label><span class="checkEmail" style="color:red"></span>
					<input type="email" value="${email}" id="email" name="email" class="validate[custom[email],required]" placeholder="Nhập email..." />
				</section>
				<section>
					<label for="password1">Mật khẩu : </label>
					<input type="password" value="${pwd}" id="password1" name="pwd" class="validate[required]" placeholder="123456" />
				</section>
				<section>
					<label for="password2">Nhập lại mật khẩu : </label>
					<input type="password" id="password2" class="validate[required,equals[password1]]" placeholder="123456" />
				</section>
				<section>
					<label for="answer">Captcha: </label>
					<img src='<spring:url value="/captcha5.htm" />' />
					<br />
					<br />
					<input id="answer" name="answer" class="validate[required]" style="width: 200px;"/><span style="color:red">${notice}</span>
				</section>
				<section>
					<button type="submit" class="button medium blue">Tạo thành viên</button>
				</section>
			</fieldset>
		</form>
	</section>
	<section class="clr"></section>
</body>
